<?php
/**
 * Created by PhpStorm.
 * User: wumengmeng <wu_mengmeng@foxmail.com>
 * Date: 2019/4/26 0026
 * Time: 14:35
 */

namespace HiCommon\Service;

use HiCommon\Repository\AdminsRepository;
use HiCommon\Repository\LogRepository;
use HiCommon\Repository\ShopUserRepository;
use HiCommon\Repository\UsersRepository;
use Illuminate\Support\Facades\Hash;
use Modules\Admin\Service\LogService;
use HiCommon\Repository\CouponsRepository;
use HiCommon\Repository\CouponGrantDetailRepository;
class LoginService extends BaseService
{



//    /**
//     *  新用户注册赠送优惠券
//     *  hinq 2019 11 28
//     *  $user_id   新注册用户的主键id
//     **/
//    public function register_gift( int $user_id ){
//        if( empty( $user_id ) ){
//            return hello_error('参数错误');
//        }
//        //获取设置的信息
//        $arr_info = LogRepository::get_set_field_info_log( (string) 'register_gift' )->toArray();
//        $info = $arr_info['data'][0];
//        if( $info['open'] == 'off' ){  //不发放礼包
//            return hello_success('ok');
//        }
//        //获取所有的优惠券信息
//        $coupons = array_unique( $info['coupon_id'] );
//        $arr_option['field'] = ['pid','validity_at','id'];
//        $arr_coupon = CouponsRepository::get_all_by_whereIn((array) $coupons , (array) $arr_option )->toArray();
//        $temp = [];
//        foreach ( $arr_coupon as $key => $value ){
//            $temp[$value['id']] = $value;
//        }
//        foreach ( $info['coupon_id'] as $key=>$vo ){
//            for ( $i = 1 ; $i <= $info['price'][$key] ; $i++ ){
//                $data['user_id'] = $user_id;
//                $data['coupon_id'] = $temp[$vo]['id'];
//                $data['pid'] = $temp[$vo]['pid'];
//                $data['over_at'] = time() + $temp[$vo]['validity_at'] * 3600 * 24;
//                $data['integral'] = 0;
//                $data['ticket_num'] = set_coupons_ticket_num( $temp[$vo]['pid'] );
//                $data['msg'] = '新用户注册奖励';
//                $data['status'] = 1;
//                $data['type'] = 4;
//                CouponGrantDetailRepository::add_one( (array) $data );
//            }
//        }
//        return hello_success('ok');
//    }

}